package com.study.base.io.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tan on 2017/7/18.
 */
public class Test {
	public static void main(String[] args) throws IOException {
		//一个channel 注册到多个selector。 key是否相同? key不同
		//一个channel 可以注册到多个selector。 单不能再同一个selector中注册多个同样的channel

		List<Selector> selectors = new ArrayList<>();
		for (int i = 0; i < 4; i++) {
			selectors.add(Selector.open());
		}

		ServerSocketChannel serverSocket = ServerSocketChannel.open();
		serverSocket.socket().bind(new InetSocketAddress(82));
		serverSocket.configureBlocking(false);

		List<SelectionKey> keys = new ArrayList<>();
		for (Selector selector : selectors) {
			keys.add(serverSocket.register(selector, SelectionKey.OP_ACCEPT));
		}

		System.out.println("jjj");
	}
}
